home *** CD-ROM | disk | FTP | other *** search
/ Champak 123 / (Vol 123) Jan 13 2011.iso / Games / the-incredibles-save-the-day.swf / scripts / __Packages / mx / utils / StringTokenParser.as < prev   
Text File  |  2011-01-13  |  4KB  |  117 lines

  1. class mx.utils.StringTokenParser
  2. {
  3.    static var tkEOF = -1;
  4.    static var tkSymbol = 0;
  5.    static var tkString = 1;
  6.    static var tkInteger = 2;
  7.    static var tkFloat = 3;
  8.    var _index = 0;
  9.    var _token = "";
  10.    function StringTokenParser(source, skipChars)
  11.    {
  12.       this._source = source;
  13.       this._skipChars = skipChars != undefined ? skipChars : null;
  14.    }
  15.    function get token()
  16.    {
  17.       return this._token;
  18.    }
  19.    function getPos()
  20.    {
  21.       return this._index;
  22.    }
  23.    function nextToken()
  24.    {
  25.       var _loc4_ = undefined;
  26.       var _loc2_ = undefined;
  27.       var _loc3_ = this._source.length;
  28.       this.skipBlanks();
  29.       if(this._index >= _loc3_)
  30.       {
  31.          return mx.utils.StringTokenParser.tkEOF;
  32.       }
  33.       _loc2_ = this._source.charCodeAt(this._index);
  34.       if(_loc2_ >= 65 && _loc2_ <= 90 || _loc2_ >= 97 && _loc2_ <= 122 || _loc2_ >= 192 && _loc2_ <= Infinity || _loc2_ == 95)
  35.       {
  36.          _loc4_ = this._index;
  37.          this._index = this._index + 1;
  38.          _loc2_ = this._source.charCodeAt(this._index);
  39.          while((_loc2_ >= 65 && _loc2_ <= 90 || _loc2_ >= 97 && _loc2_ <= 122 || _loc2_ >= 48 && _loc2_ <= 57 || _loc2_ >= 192 && _loc2_ <= Infinity || _loc2_ == 95) && this._index < _loc3_)
  40.          {
  41.             this._index = this._index + 1;
  42.             _loc2_ = this._source.charCodeAt(this._index);
  43.          }
  44.          this._token = this._source.substring(_loc4_,this._index);
  45.          return mx.utils.StringTokenParser.tkSymbol;
  46.       }
  47.       if(_loc2_ == 34 || _loc2_ == 39)
  48.       {
  49.          this._index = this._index + 1;
  50.          _loc4_ = this._index;
  51.          _loc2_ = this._source.charCodeAt(_loc4_);
  52.          while(_loc2_ != 34 && _loc2_ != 39 && this._index < _loc3_)
  53.          {
  54.             this._index = this._index + 1;
  55.             _loc2_ = this._source.charCodeAt(this._index);
  56.          }
  57.          this._token = this._source.substring(_loc4_,this._index);
  58.          this._index = this._index + 1;
  59.          return mx.utils.StringTokenParser.tkString;
  60.       }
  61.       if(_loc2_ == 45 || _loc2_ >= 48 && _loc2_ <= 57)
  62.       {
  63.          var _loc5_ = mx.utils.StringTokenParser.tkInteger;
  64.          _loc4_ = this._index;
  65.          this._index = this._index + 1;
  66.          _loc2_ = this._source.charCodeAt(this._index);
  67.          while(_loc2_ >= 48 && _loc2_ <= 57 && this._index < _loc3_)
  68.          {
  69.             this._index = this._index + 1;
  70.             _loc2_ = this._source.charCodeAt(this._index);
  71.          }
  72.          if(this._index < _loc3_)
  73.          {
  74.             if(_loc2_ >= 48 && _loc2_ <= 57 || _loc2_ == 46 || _loc2_ == 43 || _loc2_ == 45 || _loc2_ == 101 || _loc2_ == 69)
  75.             {
  76.                _loc5_ = mx.utils.StringTokenParser.tkFloat;
  77.             }
  78.             while((_loc2_ >= 48 && _loc2_ <= 57 || _loc2_ == 46 || _loc2_ == 43 || _loc2_ == 45 || _loc2_ == 101 || _loc2_ == 69) && this._index < _loc3_)
  79.             {
  80.                this._index = this._index + 1;
  81.                _loc2_ = this._source.charCodeAt(this._index);
  82.             }
  83.          }
  84.          this._token = this._source.substring(_loc4_,this._index);
  85.          return _loc5_;
  86.       }
  87.       this._token = this._source.charAt(this._index);
  88.       this._index = this._index + 1;
  89.       return mx.utils.StringTokenParser.tkSymbol;
  90.    }
  91.    function skipBlanks()
  92.    {
  93.       if(this._index < this._source.length)
  94.       {
  95.          var _loc2_ = this._source.charAt(this._index);
  96.          while(_loc2_ == " " || this._skipChars != null && this.skipChar(_loc2_))
  97.          {
  98.             this._index = this._index + 1;
  99.             _loc2_ = this._source.charAt(this._index);
  100.          }
  101.       }
  102.    }
  103.    function skipChar(ch)
  104.    {
  105.       var _loc2_ = 0;
  106.       while(_loc2_ < this._skipChars.length)
  107.       {
  108.          if(ch == this._skipChars[_loc2_])
  109.          {
  110.             return true;
  111.          }
  112.          _loc2_ = _loc2_ + 1;
  113.       }
  114.       return false;
  115.    }
  116. }
  117.